package com.watermoniter.other;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.watermoniter.R;
import com.watermoniter.util.WMPref;

public class SettingIPActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_ip);

        ((EditText) findViewById(R.id.edit_ip)).setText(WMPref.getInstance(this).getIP());


        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                WMPref.getInstance(SettingIPActivity.this).setIP(((EditText) findViewById(R.id.edit_ip)).getText().toString());
                Toast.makeText(SettingIPActivity.this, "保存成功！", Toast.LENGTH_SHORT).show();
                mHandler.sendEmptyMessageDelayed(0, 800);
            }
        });
    }

    Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            if (msg.what == 0) {
                finish();
            }
            return  true;
        }
    });
}

